package com.sp.method;

public class ThreadMethodExercise {
    public static void main(String[] args) throws InterruptedException {
        T3 t3 = new T3();
        Thread thread = new Thread(t3);

        for (int i = 1; i <= 10; i++) {
            System.out.println("hi");
            Thread.sleep(1000);
            if(i == 5){
                thread.start();//启动子线程 输出 hello...
                thread.join();//立即将t3子线程，插入到main线程，让t3先执行
            }
        }
    }
}

class T3 implements Runnable {

    private int count = 0;
    @Override
    public void run() {
        while (true) {
            System.out.println("hello " + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (count == 10){
                System.out.println("子线程退出");
                break;
            }
        }
    }
}
